1) Download Data

path_metro_grades <- here("data", "metro-grades.csv")
path_zone_blocks <- here("data", "zone-block-matches.csv")
path_blocks <- here("data", "blocks.rds")
path_census_states <- here("data", "states.rds")

if(params$regenerate_data || 
   !file.exists(path_metro_grades) || 
   !file.exists(path_metro_grades)){
  source(here("R", "download_538_data.R"))
}

metro_grades <- read_csv(path_metro_grades)
zone_blocks <- read_csv(path_zone_blocks)


if(params$regenerate_data || !file.exists(path_blocks)){
  source(here("R", "download_census_blocks.R"))
}

if(params$regenerate_data || !file.exists(path_census_states)){
  source(here("R", "download_census_states.R"))
}

2) Reproduce Plots 1 and 2

2.a) Cleveland Bar Plot

source(here("R", "visualization_cleveland.R"))
cleveland_bar(metro_grades)

2.b) Nationwide Pie Charts

states <- readRDS(path_census_states)

source(here("R", "visualization_us.R"))
us_scatterpie_grid(metro_grades, states)

3) Reproduce Plot 3: Pittsburgh HOLC Map

3.a) Calculate Buffer Zone to Map

# Calculate Buffer Zone
path_blocks_buffer <- here("data", "blocks_buffer.rds")
path_bound <- here("data", "bound.rds")

if(params$regenerate_data || 
   !file.exists(path_blocks_buffer) ||
   !file.exists(path_bound)){
  source(here("R", "create_buffer_zone.R"))
}

3.b) Sample Pittsburgh Surrounding Area

## Perform Sampling of Pittsburgh

if(params$regenerate_data || 
   !file.exists(here("data","sampled_hispanic.rds")) ||
   !file.exists(here("data","sampled_other.rds")) ||
   !file.exists(here("data","sampled_white.rds")) ||
   !file.exists(here("data","sampled_black.rds")) ||
   !file.exists(here("data","sampled_asian.rds"))
   ){
  source(here("R", "sample_population.R"))
}
## [1] "Sampling Hispanic Population..."
## [1] "Sampling Other Race Population..."
## [1] "Sampling Asian Population..."
## [1] "Sampling Black Population..."
## [1] "Sampling White Population..."

3.c) Sample Pittsburgh HOLC blocks

## Perform sampling of individual HOLC blocks

# To reduce run time, create a special version with downsampled population
# This only plots 1/10th of the population

source(here("R","sample_holc.R"))

blocks_buffer <- readRDS(path_blocks_buffer)
holc_samp <- blocks_buffer %>% 
  mutate(
    hispanic = round(hispanic/10),
    white = round(white/10),
    black = round(black/10),
    asian = round(asian/10),
    other_race = round(other_race/10)
  ) %>% inner_join(zone_blocks, by=c("GEOID"="block_geoid20"))


for(grade in c("A","B","C","D")){
  if(params$regenerate_data ||
    !file.exists(here("data",sprintf("sampled_white_%s.rds", grade))) ||
     !file.exists(here("data",sprintf("sampled_black_%s.rds", grade))) ||
     !file.exists(here("data",sprintf("sampled_asian_%s.rds", grade))) ||
     !file.exists(here("data",sprintf("sampled_hispanic_%s.rds", grade))) ||
     !file.exists(here("data",sprintf("sampled_other_%s.rds", grade)))){
    map_grade(holc_samp, grade)
  }
}
## [1] "Saving Hispanic A..."
## [1] "Saving Other A..."
## [1] "Saving Asian A..."
## [1] "Saving Black A..."
## [1] "Saving White A..."
## [1] "Saving Hispanic B..."
## [1] "Saving Other B..."
## [1] "Saving Asian B..."
## [1] "Saving Black B..."
## [1] "Saving White B..."
## [1] "Saving Hispanic C..."
## [1] "Saving Other C..."
## [1] "Saving Asian C..."
## [1] "Saving Black C..."
## [1] "Saving White C..."
## [1] "Saving Hispanic D..."
## [1] "Saving Other D..."
## [1] "Saving Asian D..."
## [1] "Saving Black D..."
## [1] "Saving White D..."

3.d) Initialize Visualization

source(here("R","visualization_pittsburgh.R"))

bound <- readRDS(path_bound)

holc_plots <- construct_holc_map()

PA_plot <- construct_PA(states, metro_grades)

surrounding_bar <- construct_surrounding_bar(blocks_buffer)

Pittsburgh, PA:

“BEST”

“DESIRABLE”

“DECLINING”

“HAZARDOUS”